package com.cljz.makepassenger.present.activity;

import com.cljz.makepassenger.base.BaseP;
import com.cljz.makepassenger.model.net.api.Api;
import com.cljz.makepassenger.model.net.bean.IndexInfoBean;
import com.cljz.makepassenger.ui.activity.SettingActivity;

import java.util.HashMap;

import cn.droidlover.xdroidmvp.net.ApiSubcriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;
import cn.droidlover.xdroidmvp.net.diy.Base64Utils;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/4/6 0006.
 */

public class SettingP extends BaseP<SettingActivity> {

    public void getLetter() {
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("token", getToken());
        paramsMap.put("city_name", "成都");
        String body = Base64Utils.enCode(gson.toJson(paramsMap));
        RequestBody requestBody = RequestBody.create(okhttp3.MediaType.parse("text/plain;charset=UTF-8"), body);
        Api.getResponseInfoAPI().getIndexInfoData(requestBody)
                .compose(XApi.<IndexInfoBean>getApiTransformer())
                .compose(XApi.<IndexInfoBean>getScheduler())
                .compose(getV().<IndexInfoBean>bindToLifecycle())
                .subscribe(new ApiSubcriber<IndexInfoBean>() {
                    @Override
                    protected void onFail(NetError error) {
//                        L.e("msg","执行了失败的步奏");
                    }

                    @Override
                    public void onNext(IndexInfoBean indexInfoBean) {
                        if ("0".equals(indexInfoBean.getError_code())) {
                            getV().showLetter(indexInfoBean.getData());
     //                       L.e("msg","有登录的话就有数据");
                        } else if ("1000".equals(indexInfoBean.getError_code())) {
                            getV().loginOvertime(1);
     //                       L.e("msg","没有登录的话就没有数据");
                        } else {
                            getV().showLetterFail(indexInfoBean.getMsg());
     //                       L.e("msg","执行了第三步的步奏");
                        }
                    }
                });
    }
}
